package cn.lizhangqu.kb.service;

import android.util.Log;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.litepal.crud.DataSupport;

import java.util.List;

import cn.lizhangqu.kb.model.Article;

/**
 * Created by 柯尊诚 on 2015/11/5.
 * kzc
 */
public class LgrgService {
    private static volatile LgrgService lgrgService;
    private LgrgService(){}
    public static LgrgService getLgrgService() {
        if (lgrgService == null) {
            synchronized (LgrgService.class) {
                if (lgrgService == null)
                    lgrgService = new LgrgService();
            }
        }
        return lgrgService;
    }

    public boolean save(Article article) {
        return article.save();
    }

    public List<Article> findAll() {
        return DataSupport.findAll(Article.class);
    }

    public void parseArticle(String content) {
        Document doc = Jsoup.parse(content);
        Elements elements = doc.select("ul#atArticles");
        int rowNum = elements.size();
        Log.d("xxxid", rowNum+"");
        for (int i = 0; i < rowNum - 1; i++) {
            Element element = elements.get(0).child(i);

            Log.d("xxxx", element.child(0).attr("href"));
            Log.d("xxxx1",element.child(0).text() + "<==>" + i);
            Log.d("xxxx2",element.child(1).text());
        }
        Article article = new Article();
//        article.set
    }
}
